package com.mvp.shq.washer.ui.news;

import com.mvp.shq.washer.entity.BaseResult;
import com.mvp.shq.washer.entity.MessageBean;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/8/24.
 */

public class NewsPresenter extends NewsConstract.Presenter {
    @Override
    public void onStart() {
    }

    @Override
    void getMsgs() {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getId();
        model.getMessages(token,userId)
                .subscribe(new BaseObserver<List<MessageBean>>(view) {
                    @Override
                    protected void onSuccees(BaseResult<List<MessageBean>> t) throws Exception {
                        if (t.isError()){
                            view.msgFail(t.getMsg());
                        }else {
                            view.msgSuccess(t.getData());
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        view.msgFail("未知错误");
                    }
                });
    }
}
